package com.jsnkj.basic.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.jsnkj.basic.R
import com.jsnkj.basic.bean.ApprenticeEntity


class MyApprenticeAdapter(
    val context: Context,
    private val itemBeans: List<ApprenticeEntity>
) :
    RecyclerView.Adapter<MyApprenticeAdapter.ViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view: View =
            LayoutInflater.from(parent.context)
                .inflate(R.layout.rv_item_my_apprentice, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val item = itemBeans[position]
//        LogUtils.e("我的徒弟列表数据：" + item.toString())
        Glide.with(context).load(item.avatar).into(holder.ivIcon)
        holder.tvTitle.setText(item.nickname)
        holder.tvMember.setText("会员ID：${item.uuid}")

        if (item.total_commission.isNullOrEmpty()) {
            holder.tvMoney.setText("+0.0元")
        } else {
            holder.tvMoney.setText("+${item.total_commission}元")
        }

    }

    override fun getItemCount(): Int {
        return itemBeans.size
    }

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var conLayoutItem: ConstraintLayout
        var ivIcon: ImageView
        var tvTitle: TextView
        var tvMember: TextView
        var tvMoney: TextView

        init {
            conLayoutItem = itemView.findViewById<ConstraintLayout>(R.id.con_layout_item)
            ivIcon = itemView.findViewById<ImageView>(R.id.img_avatar)
            tvTitle = itemView.findViewById<TextView>(R.id.tv_title)
            tvMember = itemView.findViewById<TextView>(R.id.tv_member)
            tvMoney = itemView.findViewById<TextView>(R.id.tv_money)
        }
    }


    interface onItemClickListener {
        fun onItemCallBack(position: Int)
    }
}